package com.luoxin.servicedriveruser.service;

import com.luoxin.internalcommon.dto.ResponseResult;
import com.luoxin.internalcommon.entity.DriverUserWorkStatus;
import com.luoxin.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DriverUserWorkStatusService {
    @Autowired
    private DriverUserWorkStatusMapper driverUserWorkStatusMapper;
    public ResponseResult changeWorkStatus(Long driverId, Integer workStatus){
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("driver_id", driverId);
        List<DriverUserWorkStatus> driverUserWorkStatuses = driverUserWorkStatusMapper.selectByMap(queryMap);

        DriverUserWorkStatus userWorkStatus = driverUserWorkStatuses.get(0);
        userWorkStatus.setGmtModified(LocalDateTime.now());
        userWorkStatus.setWorkStatus(workStatus);

        driverUserWorkStatusMapper.updateById(userWorkStatus);
        return ResponseResult.success();
    }
}
